/* eslint-disable no-undef */
Proj4js.defs(
  'EPSG:0',
  '+proj=tmerc +lat_0=0 +lon_0=113.283333333 +k=1 +x_0=39980 +y_0=-2329620 +ellps=GRS80 +units=m +no_defs',
)
var gz2k = L.Proj.CRS('EPSG:0', {
  origin: [-382563.32, 501405.69],
  resolutions: [
    1222.9948988231311, 611.49744941156553, 305.74872470578276, 152.87436235289138,
    76.437179853526374, 38.218591249682497, 19.109294301921938, 9.5546471509609692,
    4.7773235754804846, 2.3886631106595546, 1.1943315553297773, 0.59716577766488865,
    0.29858288883244433, 0.14929144441622216,
  ],
  //bounds: L.bounds([ -382563.32 , -107774.47],  [467772.54 , 501405.69])
})
window.GZ2000 = new L.Proj.CRS('EPSG:0')
function initMap(id) {
  // 初始化地图信息
  var map = L.map(id, {
    crs: gz2k,
    center: [23.230134, 113.302642],
    zoom: 5,
    maxZoom: 13,
    minZoom: 0,
    zoomControl: true,
    logoControl: false,
    attributionControl: false,
  })
  // var url = 'http://192.168.88.177:8090/iserver/services/map-tpk-BaiYunQuCunJieXian/rest/maps/%E7%99%BD%E4%BA%91%E5%8C%BA%E6%9D%91%E7%95%8C%E7%BA%BF';

  //添加图层
  var sl = L.tileLayer.wms('http://192.168.88.177:8000/service?', {
    layers: 'ditu_baiyun',
    format: 'image/png',
    transparent: true,
    attribution: '&copy; MapProxy'
  });
  sl.addTo(map)
  return map
}
// 一张图底图
function initTianDiTuMap(id) {
  window.basemap = new Array()
  // 初始化地图信息
  var map = L.map(id, {
    crs: L.CRS.TianDiTu_WGS84,
    center: [23.26, 113.29],
    zoom: 10,
    maxZoom: 17,
    minZoom: 4,
    zoomControl: false,
    logoControl: false,
    attributionControl: false,
    preferCanvas: true,
  })
  var tdtv1 = L.supermap
    .tiandituTileLayer({
      key: '1d109683f4d84198e37a38c442d68311',
    })
    .addTo(map)
  var tdtv2 = L.supermap
    .tiandituTileLayer({
      isLabel: true,
      key: '1d109683f4d84198e37a38c442d68311',
    })
    .addTo(map)
  window.basemap.push(tdtv1, tdtv2)
  return map
}
export { initMap, initTianDiTuMap }
